package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.api.SysCompanyControllerApi;
import com.nineclock.system.dto.SysChangeMainManagerDTO;
import com.nineclock.system.dto.SysCompanyDTO;
import com.nineclock.system.pojo.SysCompanyUser;
import com.nineclock.system.service.SysCompanyService;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/company")
public class SysCompanyController implements SysCompanyControllerApi {

    @Autowired
    private SysCompanyService sysCompanyService;

    @GetMapping
    @Override
    public Result findInfo() {
        return Result.success(sysCompanyService.findInfo());
    }

    @PostMapping("/uploadOSS")
    @Override
    public Result uploadOSS(MultipartFile file) {
        String url = sysCompanyService.uploadOSS(file);
        return Result.success(url);
    }

    @PutMapping
    @Override
    public Result updateInfo(@RequestBody SysCompanyDTO dto) {
        sysCompanyService.updateInfo(dto);
        return Result.success();
    }


    @PostMapping("/config/admin")
    @Override
    public Result changeSysAdmin(@RequestBody SysChangeMainManagerDTO dto) {
        sysCompanyService.changeSysAdmin(dto);
        return Result.success();
    }

    @Autowired
    private SysCompanyUserService sysCompanyUserService;

    @GetMapping("/getCurrentAdmin")
    @Override
    public Result findCurrentAdmin() {
        SysCompanyUser sysCompanyUser = sysCompanyUserService.findCurrentAdmin();
        return Result.success(sysCompanyUser);
    }

}
